package com.example.zlw.dem24;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @program: Zlw
 * @description:
 * @author: 诸葛龙辰
 * @create: 2022-11-09 22:17
 **/
public class FunSum {
    private Method1 method1;

    public FunSum(Method1 method2) {
        this.method1 = method2;
    }
    public Method1 getMethod(){
        ClassLoader classLoader = method1.getClass().getClassLoader();
        Class<?>[] interfaces = method1.getClass().getInterfaces();
        InvocationHandler invocationHandler = new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                look();
                Object invoke = method.invoke(method1, objects);
                return invoke;
            }
        };
        Object o = Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
        return (Method1) o;
    }

    public void look(){
        System.out.println("请输入正确的数值进行计算");
    }
    public void  show(){
        System.out.println("最终计算的结果如下：");
    }

}
